<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%>
<c:set var="path" value="../..${ctx}/define/action" />
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Pagination 分页表格</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link href="${ctx}/demo/demo.css" rel="stylesheet" type="text/css" />
<script src="${ctx}/scripts/boot.js" type="text/javascript"></script>
<script src="${ctx}/common/common.js" type="text/javascript"></script>
<style type="text/css">
html,body {
	margin: 0;
	padding: 0;
	border: 0;
	width: 100%;
	height: 100%;
	overflow: hidden;
}
</style>
</head>
<body>
<form id="form1" method="post">
	<div id="toolbar1" class="mini-toolbar" style="padding:2px;">
	    <table style="width:100%;">
	        <tr>
	        <td style="width:100%;">
	            <a class="mini-menubutton" iconCls="icon-add" plain="true" menu="#popupMenu">新增</a>
	            <a class="mini-button" iconCls="icon-edit" onclick="modify()" plain="true">修改</a>
	            <a class="mini-button" iconCls="icon-save" onclick="saveAll()" plain="true">保存</a>
	            <a class="mini-button" iconCls="icon-remove" onclick="deleteAction()" plain="true">删除</a>
	            <span class="separator"></span>
	            <a class="mini-button" iconCls="icon-download" plain="true">导入</a>
	            <a class="mini-button" iconCls="icon-upload" plain="true">导出</a>
	        </td>
	        <td style="white-space:nowrap;">
	        	<label style="font-family:Verdana;">操作名称: </label>
	            <input name="action_name" field="action_name" class="mini-textbox" />
	            <label style="font-family:Verdana;">操作分类: </label>
	            <input name="action_sort" field="action_sort" class="mini-textbox" />
	            <input type="button" value="查找" onclick="search()"/>
	            </td>
	        </tr>
	    </table>
	</div>
</form>

    <!--menu-->
    <ul id="popupMenu" class="mini-menu" style="display:none;">
	    <li iconCls="icon-add" onclick="addActions();" >操作单元集</li>
	    <li iconCls="icon-add" onclick="addActionSearch();" >查询操作单元</li>
	    <li iconCls="icon-add" onclick="addActionUpdate();" >更新操作单元</li>
	    <li iconCls="icon-add" onclick="addActionDefine();" >自定义操作单元</li>
    </ul>

	<div class="mini-fit">
		<div id="grid1" class="mini-datagrid"
			style="width: 100%; height: 100%;" borderStyle="border:0;"
			url="${path}/list.html"
			allowCellSelect="true" allowCellEdit="false" allowSortColumn="false" showPager="false" showModified="true">
			<div property="columns">
				<div name="name" field="name" headerAlign="center" allowSort="true" width="100">
					操作单元名称 <input property="editor" class="mini-textbox" style="width: 100%;" minWidth="100" />
				</div>
				<div name="sort" field="sort" headerAlign="center" allowSort="true" width="200">
					分类 <input property="editor" class="mini-textbox" style="width: 100%;" minWidth="200" />
				</div>
				<div name="description" field="description" headerAlign="center" allowSort="true" width="300">
					描述 <input property="editor" class="mini-textbox" style="width: 100%;" minWidth="300" />
				</div>
			</div>
		</div>
	</div>

<script type="text/javascript">
mini.parse();
var tree = mini.get("tree1");
var grid = mini.get("grid1");
var form = new mini.Form("#form1");

function search() {
	var data = form.getData();
	grid.loading("查询中，请稍后......");
	$.ajax({
		url : "${path}/list.html",
		data : {
			name : data.action_name,
			sort : data.action_sort
		},
		type : "post",
		success : function(text) {
			grid.setData(text);
		},
		error : function(jqXHR, textStatus, errorThrown) {
			showErr(jqXHR.responseText);
			grid.unmask();
		}
	});
}
function addRow() {
	var node = tree.getSelectedNode();
	if (node) {
		var newRow = {
		};
		newRow.dept_id = node.name;
		grid.addRow(newRow, grid.getData().length);
	}
}
function removeRow() {
	var rows = grid.getSelecteds();
	if (rows.length > 0) {
		grid.removeRows(rows, true);
	}
}
function saveData() {
	var data = grid.getChanges();
	var json = mini.encode(data);
	alert(json);
	grid.loading("保存中，请稍后......");
	$.ajax({
		url : "../data/AjaxService.aspx?method=SaveEmployees",
		data : {
			data : json
		},
		type : "post",
		success : function(text) {
			grid.reload();
		},
		error : function(jqXHR, textStatus, errorThrown) {
			alert(jqXHR.responseText);
		}
	});
}

function addActions() {
    var row = grid.getSelected();
    if (row) {
        mini.open({
            url: bootPATH + "../demo/CommonLibs/EmployeeWindow.html",
            title: "编辑员工", width: '840px', height: '600px',
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "edit", id: row.id };
                iframe.contentWindow.SetData(data);
                
            },
            ondestroy: function (action) {
                grid.reload();
                
            }
        });
        
    } else {
        alert("请选中一条记录");
    } 
}	
function addActionSearch() {
    mini.open({
        url: "../..${ctx}/common/view.html?jsp=define/action/action_search",
        title: "添加查询操作单元", width: 920, height: 600,
        onload: function () {
           // var iframe = this.getIFrameEl();
            //var data = { action: "edit", id: row.id };
           // iframe.contentWindow.SetData(data);
        },
        ondestroy: function (action) {
            //grid.reload();
        }
    });
}
function addActionUpdate() {
    mini.open({
        url: "../..${ctx}/common/view.html?jsp=define/action/action_update",
        title: "添加查询操作单元", width: 800, height: 460,
        onload: function () {
           // var iframe = this.getIFrameEl();
            //var data = { action: "edit", id: row.id };
           // iframe.contentWindow.SetData(data);
        },
        ondestroy: function (action) {
            //grid.reload();
        }
    });
}
function addActionDefine() {
    var row = grid.getSelected();
    if (row) {
        mini.open({
            url: bootPATH + "../demo/CommonLibs/EmployeeWindow.html",
            title: "编辑员工", width: 600, height: 360,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "edit", id: row.id };
                iframe.contentWindow.SetData(data);
                
            },
            ondestroy: function (action) {
                grid.reload();
                
            }
        });
        
    } else {
        alert("请选中一条记录");
    } 
}

function modify() {
    var row = grid.getSelected();
    if (row) {
    	var _width,_height;
    	var _url = "../..${ctx}/common/view.html?jsp=define/action/action_" + row.actionType;
    	if(row.actionType == "search"){
    		_width = 920;
    		_height = 600;
    	}else if(row.actionType == "update"){
    		_width = 800;
    		_height = 460;
    	}else if(row.actionType == "define"){
    		_width = 600;
    		_height = 360;
    	}
    	
        mini.open({
            url: _url,
            title: "编辑员工", width: _width, height: _height,
            onload: function () {
               // var iframe = this.getIFrameEl();
                //var data = { action: "edit", id: row.id };
                //iframe.contentWindow.SetData(data);
                
            },
            ondestroy: function (action) {
                grid.reload();
            },
    		error : function(jqXHR, textStatus, errorThrown) {
    			alert(jqXHR.responseText);
    		}
        });
        
    } else {
        alert("请选中一条记录");
    }
}

function saveAll() {
}

function deleteAction() {
	var data = grid.getChanges();
	var json = mini.encode(data);
	alert(json);
	grid.loading("保存中，请稍后......");
	$.ajax({
		url : "../data/AjaxService.aspx?method=SaveEmployees",
		data : {
			data : json
		},
		type : "post",
		success : function(text) {
			grid.reload();
		},
		error : function(jqXHR, textStatus, errorThrown) {
			alert(jqXHR.responseText);
		}
	});
}
</script>

</body>
</html>